package n14;

/**
 * 纵向扫描
 */
public class Main1 {

    public static String longestCommonPrefix(String[] strs) {
        if (strs.length == 0) {
            return "";
        }
        int length = strs[0].length();
        int count = strs.length;
        for (int i = 0; i < length; i++) {
            char c = strs[0].charAt(i);
            for (int j = 1; j < count; j++) {
                if (strs[j].length()-1<i){
                    return strs[0].substring(0,i);
                }
                char c1 = strs[j].charAt(i);
                if (i==strs[j].length()||c1!=c){
                    return strs[0].substring(0,i);
                }
            }
        }
        return strs[0];
    }

    public static void main(String[] args) {
        // String[] strs = {"flower", "flow", "flight"};
        // String[] strs = {"dog", "racecar", "car"};
        String[] strs = {"ab","a"};
        // String[] strs = {"dog"};
        System.out.println(longestCommonPrefix(strs));
    }

    /*dog
    doc
    ddd*/
}
